package com.fiveflavors.suittar.gui;


import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import com.fiveflavors.suittar.Suittar;
import com.fiveflavors.suittar.SuittarCommand;

public class SuittarHyperLinkListener implements HyperlinkListener {

	private Suittar suittar = null;
	
	public SuittarHyperLinkListener(Suittar suittar) {
		this.suittar = suittar;
	}

	public void hyperlinkUpdate(HyperlinkEvent e) {
		if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
			
			if (!e.getURL().getHost().startsWith("suittar")) {
				suittar.executeBrowser(e.getURL());
			}
			else if (e.getURL().getFile().startsWith("/setAtmark")) {
				suittar.setAtMarkUser(e.getURL().getQuery().replaceAll("id=", ""));
			}
			else if (e.getURL().getFile().startsWith("/add")){
				suittar.addFriend(e.getURL().getQuery().replaceAll("id=", ""));
			}
			else if (e.getURL().getFile().startsWith("/remove")){
				suittar.removeFriend(e.getURL().getQuery().replaceAll("id=", ""));
			}
			else if (e.getURL().getFile().startsWith("/closepane")){
				int id = Integer.parseInt(e.getURL().getQuery().replaceAll("id=", ""));
				suittar.removeTabPane(id);
			}
			else {
				SuittarCommand.setCommand(e.getURL());
				suittar.executeSuittarCommand();
			}
			
		}
	}

}
